package org.example.business.endpoint.http.event.connection;

import io.netty.channel.ChannelFutureListener;
import lombok.extern.slf4j.Slf4j;
import org.example.business.endpoint.http.HttpSocket;
import org.example.business.endpoint.http.HttpSocketManager;
import org.example.objevent.event.EventActor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SocketCleanActor implements EventActor<HttpSocket> {

    @Autowired
    private HttpSocketManager socketManager;

    @Override
    public String getWatchEvent() {
        return "CLEAN_CONNECTION";

    }

    @Override
    public void act(HttpSocket data) {

        HttpSocket removed = socketManager.delSocket(data);

        if(null != removed){
            removed.getSocketContext().close().addListener(ChannelFutureListener.CLOSE);

        }

    }

}
